home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / banging_the_metal / qdos / qdos4amiga3.lha / XCHPATCH_readme < prev   
Text File  |  1998-02-24  |  6KB  |  187 lines

  1. Short:    patch for PD XCHANGE for COPYBACK compatibility
  2. Author:   Mark J Swift
  3. Version:  1.00
  4. Uploader: msw@blackpool.ac.uk
  5.  
  6.  
  7. The BASIC program XCHPATCH_bas patches PD XCHANGE to work
  8. with 68040 and 68060 processors with COPYBACK enabled.
  9.  
  10.  
  11. ARCHIVE CONTENTS
  12.  
  13.  XCHPATCH_bas    - Patch program for PD XCHANGE
  14.  XCHPATCH_readme - This file.
  15.  
  16.  
  17. COMPATIBILITY
  18.  
  19. Works with every version of XChange that I have tried.
  20.  
  21.  
  22. WHY IS IT NECESSARY?
  23.  
  24. On machines with 68040 and 68060 processors, the efficiency of
  25. data and instruction caches can be greatly increased if COPYBACK
  26. is enabled. Enabling the COPYBACK cache can give substantial
  27. speed increases.
  28.  
  29. However doing so highlights problems with a number of programs,
  30. including Psion Xchange...
  31.  
  32. Psion Xchange contains a routine at offset $120 that relocates an
  33. internal jump table. On 68040 and 68060 this can cause problems as
  34. I shall try to explain...
  35.  
  36.  
  37.   With COPYBACK enabled, when a write to memory occurs the data is
  38.   written to the data cache but is not written through to memory.
  39.  
  40.   If the processor subsequently fetches an instruction from this
  41.   area of memory it won't get the correct value, since the correct
  42.   value will only be held in the data cache - not within memory.
  43.  
  44.  
  45. Programs that create jump tables should always flush the caches out
  46. to memory before modified jump table code is executed.
  47.  
  48. The problematic jump-table-relocation routine of Xchange is at
  49. offset $120 and continues for $BE bytes...
  50.  
  51. 00000120 48E7E0C0     movem.l   d0-d2/a0-a1,-(a7)
  52. 00000124 41FA00BC     lea       $1E2(pc),a0
  53. 00000128 224D         move.l    a5,a1
  54. 0000012A 303C00C5     move.w    #$C5,d0
  55. 0000012E 2408         move.l    a0,d2
  56. 00000130 32FC4EF9     move.w    #$4EF9,(a1)+
  57. 00000134 2218         move.l    (a0)+,d1
  58. 00000136 D282         add.l     d2,d1
  59. 00000138 22C1         move.l    d1,(a1)+
  60. 0000013A 5340         subq.w    #1,d0
  61. 0000013C 66F2         bne       $130
  62. 0000013E 2B7A65AAFFF0 move.l    $66EA(pc),-$10(a5)
  63. 00000144 41FA0098     lea       $1DE(pc),a0
  64. 00000148 D1D0         adda.l    (a0),a0
  65. 0000014A 2B4814C8     move.l    a0,$14C8(a5)
  66. 0000014E 1B7C00FF06FE move.b    #-$1,$6FE(a5)
  67. 00000154 50ED06FF     st        $6FF(a5)
  68. 00000158 422D06FB     clr.b     $6FB(a5)
  69. 0000015C 422D06FC     clr.b     $6FC(a5)
  70. 00000160 422D0701     clr.b     $701(a5)
  71. 00000164 422D068B     clr.b     $68B(a5)
  72. 00000168 1B7C001B06FD move.b    #$1B,$6FD(a5)
  73. 0000016E 422D0700     clr.b     $700(a5)
  74. 00000172 422D0702     clr.b     $702(a5)
  75. 00000176 422D0703     clr.b     $703(a5)
  76. 0000017A 2B7C0000FFFF move.l    #$FFFF,$1262(a5)
  77.          1262
  78. 00000182 2B7C000000FF move.l    #$FF,$1266(a5)
  79.          1266
  80. 0000018A 422D06F5     clr.b     $6F5(a5)
  81. 0000018E 42AD08FE     clr.l     $8FE(a5)
  82. 00000192 2B7A655AFFF4 move.l    $66EE(pc),-$C(a5)
  83. 00000198 41ED0A20     lea       $A20(a5),a0
  84. 0000019C 4258         clr.w     (a0)+
  85. 0000019E 4298         clr.l     (a0)+
  86. 000001A0 4298         clr.l     (a0)+
  87. 000001A2 41ED0CC6     lea       $CC6(a5),a0
  88. 000001A6 30FC4000     move.w    #$4000,(a0)+
  89. 000001AA 4258         clr.w     (a0)+
  90. 000001AC 4298         clr.l     (a0)+
  91. 000001AE 4280         clr.l     d0
  92. 000001B0 4EAD0438     jsr       $438(a5)     *!*!*!*!*
  93. 000001B4 20C1         move.l    d1,(a0)+
  94. 000001B6 20C2         move.l    d2,(a0)+
  95. 000001B8 5280         addq.l    #1,d0
  96. 000001BA 0C00000B     cmpi.b    #$B,d0
  97. 000001BE 66F0         bne       $1B0
  98. 000001C0 50ED126D     st        $126D(a5)
  99. 000001C4 206D14C8     move.l    $14C8(a5),a0
  100. 000001C8 D0E800EA     adda.w    $EA(a0),a0
  101. 000001CC 2B481006     move.l    a0,$1006(a5)
  102. 000001D0 422D097C     clr.b     $97C(a5)
  103. 000001D4 4EBA1E38     jsr       $200E(pc)
  104. 000001D8 4CDF0307     movem.l   (a7)+,d0-d2/a0-a1
  105. 000001DC 4E75         rts
  106.  
  107. Please note, offset $1B0 contains the instruction "jsr $438(a5)".
  108. It is important that the caches are flushed BEFORE this instruction
  109. is executed.
  110.  
  111. This can be achieved by patching out the instruction with a "jsr"
  112. to a patch routine (see PATCH: below) that flushes the caches.
  113. This routine can be inserted into Xchange by inserting new code
  114. between the job name and the first instruction.
  115.  
  116. The BASIC program XCHPATCH_bas makes all the necessary patches.
  117.  
  118. *******************************************************************
  119. *
  120. * Patch routines to fix CACHE problems in Xchange on 68040 & 68060
  121. *
  122. START:
  123.         move.l  #PATCH_END-START,d0
  124.         adda.l  d0,a6
  125.         suba.l  d0,a4
  126.         suba.l  d0,a5
  127.         bra.s   PATCH_END
  128.  
  129. PATCH:
  130.         trap    #0              enter supervisor mode
  131.         ori.w   #$0700,sr       no interrupts
  132.         bsr     FLSHCACH
  133.         andi.w  #$D8FF,sr       back into user mode
  134.         jmp     $438(a5)
  135.  
  136. *******************************************************************
  137. *
  138. * a routine to flush the caches out to memory on all processors
  139. *
  140. FLSHCACH:
  141.         movem.l d0-d2/a0,-(a7)
  142.  
  143.         moveq   #0,d0
  144.         trap    #1              get address of sys vars
  145.  
  146.         cmpi.b  #$10,$A1(a0)    no caches on 68010 or less
  147.         ble.s   FLSHCACHX
  148.  
  149.         movec   cacr,d0
  150. *                     1=clear data cache (030)
  151. *                     |       1=clear instr cache (020,030)
  152. *                     |       |
  153.         ori.w   #%0000100000001000,d0   clear caches
  154.  
  155.         cmpi.b  #$30,$A1(a0)
  156.         bls.s   FLSHCACHSET
  157.  
  158.         tst.w   d0              Check 040 bits. Only flush cache
  159.         bpl.s   FLSHCACHDCHK    if instruction cache is ON
  160.         cpusha  ic              update memory from cache
  161.         cinva   ic              invalidate cache
  162.  
  163. FLSHCACHDCHK:
  164.         tst.l   d0              Check 040 bits. Only flush cache
  165.         bpl.s   FLSHCACHSET     if data cache is ON
  166.         cpusha  dc              update memory from cache
  167.         cinva   dc              invalidate cache
  168.  
  169. FLSHCACHSET:
  170.         movec   d0,cacr         set the cache
  171.  
  172. FLSHCACHX:
  173.         movem.l (a7)+,d0-d2/a0
  174.         rts
  175.  
  176. PATCH_END:
  177.  
  178. *******************************************************************
  179.  
  180. CONTACT
  181.  
  182.   post: MARK J SWIFT          e-mail: msw@blackpool.ac.uk
  183.         175 CHURCH STREET
  184.         BLACKPOOL
  185.         LANCS
  186.         FY1 3NX
  187.